define(["drawable", "bouncer"], function(Drawable, Bouncer){
        
    
    Ball.prototype = new Drawable();
    
    function Ball(sprite) {     
        
        this.sprite = sprite;
        this.maxX = undefined;
        this.maxY = undefined;
        this.speed = 3  ;
        this.vector = [1,1];
        this.lastX = undefined;
        this.lastY = undefined;
        this.init(sprite.width, sprite.height);        
    }
    
    
    
    Ball.prototype.draw = function(context){
        
        if(this.x === undefined){
            this.maxX = context.canvas.width;    
            this.maxY = context.canvas.height;
            this.x = (this.maxX-this.w)/2;
            this.y = (this.maxY-this.h)/2;
        }
            
        context.clearRect(0,0,context.canvas.width, context.canvas.height);
      
        this.lastX = this.x;
        this.lastY = this.y;
        
        this.x += this.speed * this.vector[0];
        this.y += this.speed * this.vector[1];
        
        /* bounce on walls */
        if(this.x >= this.maxX - this.w || this.x <= 0){
            this.vector[0] *= -1;
        }
        if(this.y >= this.maxY - this.h || this.y <= 0){
            this.vector[1] *= -1;
        }
        
        /*
        draw outlines
        context.beginPath();
        context.strokeWidth = 2;
        context.strokeStyle = "#0000ff";
        context.rect(this.x, this.y, this.w, this.h);
        context.stroke();
        */
        
        context.save();
        context.translate(this.x, this.y);
        context.drawImage(this.sprite, 0, 0 );
        context.restore();        
    
        
      
    };
    
    Ball.prototype.collides = function(collisionObject){
                    
        if( this.collisionSide == collisionObject.SIDE_TOP || 
            this.collisionSide == collisionObject.SIDE_BOTTOM  ){
                
            this.vector[1] *= -1;
            this.y = this.lastY;
            
        }
        else if( this.collisionSide == collisionObject.SIDE_LEFT || 
            this.collisionSide == collisionObject.SIDE_RIGHT  ){            
                    
            this.vector[0] *= -1;
            this.x = this.lastX;
        }
    };
    
    return Ball;
});